package com.alibaba.otter.manager.biz.config.pipeline.dal;

import com.alibaba.otter.manager.biz.dto.CommonSearchDTO;
import com.alibaba.otter.manager.biz.config.pipeline.dal.dataobject.PipelineDO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Map;

/**
 * PipelineDao: 数据操作接口
 * <p>
 * 这只是一个减少手工创建的模板文件
 * 可以任意添加方法和实现, 更改作者和重定义类名
 * <p/>@author Powered By Fluent Mybatis
 */
public interface PipelineDao extends BaseMapper<PipelineDO> {

    boolean checkUnique(PipelineDO pipelineDo);

    List<PipelineDO> listByChannelIds(Long[] channelId);

    List<PipelineDO> listByDestinationCondition(String destination);

    default Page<PipelineDO> pipelinePage(CommonSearchDTO searchVo, Pageable pageable){
        QueryWrapper q = QueryWrapper.create().eq(PipelineDO::getName, searchVo.getName(), StringUtils::isNotBlank);
        return paginate(pageable.getPageNumber(), pageable.getPageSize(), q);
    }

    List<PipelineDO> listByCondition(Map<String, Object> condition);
}
